package com.marvin.spring.intercept.learning.config;

import com.marvin.spring.intercept.learning.filter.TimeFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: WebConfig
 * @Description: Spring Boot 的Filter配置
 * @Author Marvin
 * @Date 2019-05-22 19:45
 */
@Configuration
public class WebFilterConfig {

    @Bean
    public FilterRegistrationBean timeFilter(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        TimeFilter timeFilter = new TimeFilter();
        registrationBean.setFilter(timeFilter);
        // 声明那些请求地址起作用
        List<String> urls = new ArrayList<>();
        urls.add("/*");

        registrationBean.setUrlPatterns(urls);

        return registrationBean;
    }
}
